<template>
  <views class="recharge_management">
    <viewTitle :title="'银行通知'" :border="false"></viewTitle>
    <!-- 搜索栏  企业端-代理商端-服务商端 -->
    <div class="search flex flexC">
      <!-- 所属服务商-银行流水号-客户编号-记录类型 -->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="search_input flex flexR center">
          <div class="bank_statement flex flexR">
            <el-form-item label="银行流水号:">
              <el-input v-model="form.bussno" placeholder="银行流水号" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="customer_number flex flexR center">
            <el-form-item label="银行账户:">
              <el-input v-model="form.accno" placeholder="银行账户" :clearable="true"></el-input>
            </el-form-item>
          </div>
          <div class="record_type flex flexR center">
            <el-form-item label="处理状态:">
              <el-select v-model="form.status" clearable placeholder="请选择">
                <el-option
                        v-for="item in status_list"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
      </el-form>
      <!-- 充值时间  按钮 (查询、重置、导出列表、录单)-->
      <el-form ref="form" label-width="auto" :inline="true">
        <div class="pay_time flex flexR center">
          <el-form-item>
            <div class="flex flexR pay_btn_list">
              <el-button type="primary" @click="getData" icon="el-icon-search">查询</el-button>
              <el-button icon="el-icon-refresh" @click="reset()">重置</el-button>
            </div>
          </el-form-item>
        </div>
      </el-form>
    </div>


    <!-- 展示列表 -->
    <div class="table_list">
      <el-table
        border
        :data="tableData"
        style="width: 100%;max-width:none;"
        :header-cell-style="getRowClass"
        :select-on-indeterminate="true"
        :fit="true"
        :lazy="true"
        @row-click="clickRow"
        max-height="450"
      >
        <el-table-column  type="index" label="序号" ></el-table-column>
        <el-table-column prop="AbstractStr_Desc" label="业务描述"></el-table-column>
        <el-table-column prop="InAcctName" label="入账账户名称" ></el-table-column>
        <el-table-column  prop="InAcctNo" label="入账账户号码"></el-table-column>
        <el-table-column prop="InBankName" label="入账账户银行" ></el-table-column>
        <el-table-column prop="OutAcctName" label="出账账户名称" width="100"></el-table-column>
        <el-table-column prop="OutAcctNo" label="出账账户号码" width="100"></el-table-column>
        <el-table-column prop="OutBankName" label="出账账户银行" width="110" ></el-table-column>
        <el-table-column :formatter="(row) => {return $splitK(row.TranAmount)}" width="110" label="交易金额"></el-table-column>
        <el-table-column :formatter="(row) => {return row.DcFlag=='C'?'企业充值':'企业付款'}" width="110" label="操作类型"></el-table-column>
        <el-table-column prop="created_time" :formatter="timeFormat" label="通知时间"></el-table-column>
        <el-table-column prop="BussSeqNo" label="银行流水号" width="110"></el-table-column>
        <el-table-column :formatter="(row) => {return row.status==0?'未通知':'已通知'}" label="充值状态" ></el-table-column>
        <el-table-column
          prop="pay_time"
          :formatter="timeFormat"
          label="入账时间"
          v-if="isCheck || isRefuse"
        ></el-table-column>
        <el-table-column label="操作" width="170"  v-if="show_edit && getTerrace == 3">
          <div class="table_operation flex flexR" slot-scope="scope" v-show="getTerrace == 3">
            <!--  -->
            <el-button
              type="primary"
              v-if="scope.row.status==0"
              @click="showProp(scope.row.notice_id)"
            >重发通知</el-button>
          </div>
        </el-table-column>
      </el-table>
    </div>
    <div class="flex flexR paging">
      <el-pagination
        style="background:#fff; padding:10px 0"
        background
        layout="total, sizes,prev, pager, next, jumper"
        @size-change="(page_size) => {this.pagination.page_size = page_size;this.getData()}"
        @current-change="(page_size) => {this.pagination.page_start = page_size;this.getData()}"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pagination.page_size"
        :total="pagination.total_count"
        :current-page="pagination.current_page"
        :page-count="pagination.page_count"
      ></el-pagination>
    </div>
    <el-dialog title="请选择企业" :visible.sync="dialogVisible" width="30%" :before-close="hideProp">
      <el-select v-model="enterprise_id" placeholder="请选择">
        <el-option
                v-for="item in enterprise_list"
                :key="item.enterprise_id"
                :label="item.enterprise_name"
                :value="item.enterprise_id">
        </el-option>
      </el-select>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hideProp">取 消</el-button>
        <el-button @click="charge_confirm" slot="reference">确定</el-button>
      </span>
    </el-dialog>
  </views>
</template>



<script>
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      download_url: "",
      form: {
        bussno: "", //  流水号
        accno: "", //  银行状态
        status: ""
      },
     status_list: [
        { value: "", label: "全部" },
        { value: "0", label: "未通知" },
        { value: "1", label: "已通知" },
      ], //  充值状态列表
      pagination: {
        //分页数据
        page_start: 0, //搜索开始页码
        current_page: 0, //当前页码
        page_count: 0, //总页数
        page_size: 10, //每页数量
        total_count: 0 //总数量
      },
      enterprise_list: [],
      enterprise_id : "",
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      show_edit: true,
      autofocus1: true,
      autofocus2: false,
      dialogVisible: false
    };
  },
  mounted() {

    this.getData();
  },
  computed: {
    getTerrace() {
      return this.$store.state.terrace;
    },
    post_list(){
        let post = this.form;
        post.pagination = this.pagination;
        return post;
    }
  },
  methods: {
    //    修改第一行样式
    getRowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background: #FAFAFA ";
      } else {
        return "";
      }
    },
    //     点击单行
    clickRow(row, column, event) {
      console.log(row, column, event);
    },
    //    修改是否换行
    changeStyleRow(width) {
      let _width = width - 290 - 350 - 300 - 50 - 25;
      if (_width > 300) {
        this.marginLeft = 25;
      } else {
        this.marginLeft = 0;
      }
    },
    //  搜索/查询
    getData() {
        let { code, msg, data } = this.$api.sendSync(
            this.$mapapi.f_noticeList,
            this.post_list
        );
        if (code != 200 && code != 501) {
            this.tableData = [];
            this.$message.error(msg);
            return;
        }
        // this.data = data;
        this.tableData = data.list || [];
        this.pagination = data.pagination;

    },
    //  重置
    reset() {
      this.form = {
          bussno: "", //  流水号
          accno: "", //  银行状态
          status: ""
      };
      this.getData();
    },
    timeFormat(row, col, idx) {
      // console.log("查询数据-col", idx);
      return idx ? this.$moment(idx * 1000).format("YYYY-MM-DD HH:MM:SS") : "";
    },
    exportExcel() {
      this.$import_excal(this.download_url || "");
    },
    changeTime() {
      if (this.pay_time) {
        this.form.charge_time_start = this.pay_time[0]/1000
        this.form.charge_time_end = this.pay_time[1]/1000
      } else {
        this.form.charge_time_start = "";
        this.form.charge_time_end = "";
      }
    },
    getEnterpriseList() {

        let { code, msg, data } = this.$api.sendSync(
          this.$mapapi.f_enterpriseList,
          {
            status : 1,
            pagination: {
              //分页数据
              page_start: 1, //搜索开始页码
              page_size: 100000 //每页数量
            }
          }
        );
        if (code != 200 && code != 501) {
          console.log(msg);
          return;
        } else {
          this.enterprise_list =data.list;
        }

    },
      showProp(notice_id){
          this.notice_id = notice_id;
          this.dialogVisible = true;
      },
      hideProp(){
          this.dialogVisible = false;
      },
    charge_confirm() {

      this.$confirm("你确定重发通知么, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let { code, msg } = this.$api.sendSync(this.$mapapi.f_bindEnterprise, {
            notice_id: this.notice_id,
            enterprise_id: this.enterprise_id,
        });
        if (code != 200) {
          this.$message.error(msg);
          return;
        }
        this.getData();
        this.$message({
          type: "success",
          message: "审核成功!"
        });
      });
    },

    // 按钮展示
    btn_show(list) {
      let newList = [];
      if (Array.isArray(list)) {
        list.forEach((v, k) => {
          if (v.charge_status == 1) {
            newList.push(11);
          }
        });
        if (newList.length > 0) {
          this.show_edit = true;
        } else {
          this.show_edit = false;
        }
      }
    }
  },
  created() {
    this.getEnterpriseList();
  }
};
</script>


<style lang="less" :scope="true"  src="@/style/account/recharge_management.less" >
</style>